<?php
/*
 * @Author: Wulala
 * @Date: 2025-03-25 15:21:48
 * @LastEditTime: 2025-04-15 17:28:16
 * @LastEditors: Wulala
 * @Description: 
 * @FilePath: \exchange\app\api\controller\order\Order.php
 * 可以输入预定的版权声明、个性签名、空行等
 */

namespace app\api\controller\order;

use app\common\controller\ApiController;
use think\exception\ValidateException;
use app\api\model\Order as OrderModel;
use think\Request;

class Order extends ApiController
{
    // 商品下单
    public function placeOrder(Request $request)
    {
        $params = $request->post();

         try {
            validate([
                'appid'  => 'require',
                'timestamp'   => 'require',
                'sign' => 'require',    
                'shop_order_no' => 'require',    
                'app_user_id' => 'require',    
                'app_user_name' => 'require',    
                'sent_to_user' => 'require',    
                'sent_to_address' => 'require',    
                'sent_to_tel' => 'require',    
                'goods_arr' => 'require'
            ])->message([
                'appid.require'  => 'appid必须传递',
                'timestamp.require'   => 'timestamp必须传递',
                'sign.require' => 'sign必须传递',    
                'shop_order_no.require' => 'shop_order_no必须传递',    
                'app_user_id.require' => 'app_user_id必须传递',    
                'app_user_name.require' => 'app_user_name必须传递',    
                'sent_to_user.require' => 'sent_to_user必须传递',    
                'sent_to_address.require' => 'sent_to_address必须传递',    
                'sent_to_tel.require' => 'sent_to_tel必须传递',    
                'goods_arr.require' => 'goods_arr必须传递'  
            ])->check($params);
        } catch (ValidateException $e) {
            output_error($e->getError());
        }
         // 处理逻辑
         $model=new OrderModel();
         $data=$model->placeOrder($params);
         
         if($data["success"]){
             output_success('success', []);
         }else{
             output_error($data["msg"]);
         }
    }

    // usdt/paypal下单
    public function placeCash(Request $request)
    {
        $params = $request->post();

         try {
            validate([
                'shop_order_no'  => 'require',
                'address'  => 'require',
                'appid'  => 'require',
                'money_type' => 'require',    
                'price' => 'require',    
                'app_user_id' => 'require',    
                'app_user_name' => 'require',    
            ])->message([
                'shop_order_no.require'  => 'shop_order_no必须传递',  
                'address.require'  => 'address必须传递',  
                'appid.require'  => 'appid必须传递',  
                'money_type.require' => 'money_type必须传递',    
                'price.require' => 'price必须传递',    
                'app_user_id.require' => 'app_user_id必须传递',    
                'app_user_name.require' => 'app_user_name必须传递',    
            ])->check($params);
        } catch (ValidateException $e) {
            output_error($e->getError());
        }
         // 处理逻辑
         $model=new OrderModel();
         $data=$model->placeCash($params);
         
         if($data["success"]){
             output_success('success', []);
         }else{
             output_error($data["msg"]);
         }
    }
    
}